<template>
  <div class="shuzizhuanji w" ref="shuzizhuanjiDom">
    <GlobalTitle title="数字专辑" @titleClick="toAlbumPage" />

    <!-- 骨架屏 -->
    <div class="content" v-if="list.length === 0">
      <div class="content_item" v-for="item in 8" :key="item">
        <el-skeleton animated :throttle="500">
          <template slot="template">
            <el-skeleton-item
              variant="image"
              style="height: 224px; width: 224px"
            />
            <el-skeleton-item
              variant="p"
              style="height: 20px; width: 224px; margin: 10px 0"
            />
            <el-skeleton-item variant="p" style="height: 20px; width: 224px" />
          </template>
        </el-skeleton>
      </div>
    </div>

    <div class="content" v-else>
      <div class="content_item" v-for="item in list" :key="item.albumId">
        <div class="content_item_img">
          <GlobalImageDeep
            :url="item.coverUrl"
            :imgWidth="224"
            :imgHeight="224"
          />
          <!-- 播放按钮 -->
          <GlobalPlayMask
            :maskWidth="64"
            :maskHeight="64"
            @maskClick="toAlbumDetailsPage(item.albumId)"
          />
        </div>
        <p class="one_txt_cut" @click="toAlbumDetailsPage(item.albumId)">
          {{ item.albumName }}
        </p>
        <i class="one_txt_cut"> {{ item.artistName }}</i>
      </div>
    </div>
  </div>
</template>

<script>
// 加载 观测 DOM 是否进入可视区的方法
import ObserverDomToScreen from "../../../../../utils/ObserverDomToScreen.js";
import { getShuziAlbum } from "../../../../../api/homeApi";
export default {
  name: "shuzizhuanji",
  components: {},
  data() {
    return {
      list: [],
    };
  },
  created() {},
  mounted() {
    ObserverDomToScreen(this.$refs.shuzizhuanjiDom, this.getShuziAlbum);
  },
  methods: {
    async getShuziAlbum() {
      try {
        const result = await getShuziAlbum();
        if (result.code === 200) {
          this.list = result.products.slice(0, 8);
          console.log("数字专辑", this.list);
        }
      } catch (error) {}
    },
    toAlbumDetailsPage(id) {
      this.$router.push(`/albumDetails/${id}`);
    },
    toAlbumPage() {
      this.$router.push("/album");
    },
  },
  computed: {},
};
</script>

<style lang="less" scoped>
.shuzizhuanji {
  /deep/ .el-image img {
    border-radius: 8px;
  }

  .content {
    display: flex;
    justify-content: space-between;
    flex-wrap: wrap;
    .content_item {
      height: 316px;
      width: 288px;
      font-size: 14px;

      &:hover {
        /deep/ .playMask .play {
          display: block;
          cursor: pointer;
        }
      }

      .content_item_img {
        position: relative;
        width: 224px;
        height: 224px;
        &::before {
          content: "";
          position: absolute;
          top: 0;
          left: 30px;
          width: 100%;
          height: 100%;
          background: url("../../../../../assets/images/album-cover-gold.png")
            no-repeat center;
        }
      }
      p {
        width: 224px;
        color: #333333;
        margin-top: 10px;
        margin-bottom: 10px;
        &:hover {
          color: @globalColor;
          // animation: bounce 1s;
          cursor: pointer;
        }
      }
      i {
        width: 224px;
        display: block;
        color: #999999;
        &:hover {
          color: @globalColor;
          // animation: bounce 1s;
          cursor: pointer;
        }
      }
    }
  }
}
</style>
